package com.pe1n.yangtaopai.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.pe1n.yangtaopai.R;
import com.pe1n.yangtaopai.bean.FindGoodsBean;
import com.pe1n.yangtaopai.page.detail.view.activity.DetailActivity;

import java.util.List;

/**
 * Created by Pe1n on 2016/11/27.
 */

public class MyFindGoodsAdapter extends RecyclerView.Adapter<MyFindGoodsAdapter.MyViewHolder> {

    private Context mContext;
    private List<FindGoodsBean.DataBean.ProdsInfoBean> mList;

    public MyFindGoodsAdapter(Context mContext, List<FindGoodsBean.DataBean.ProdsInfoBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public MyFindGoodsAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_find_goods_layout,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyFindGoodsAdapter.MyViewHolder holder, final int position) {
        Glide.with(mContext).load(mList.get(position).getPicUrl()).placeholder(R.drawable.place_holder).into(holder.imageViewImg);
        holder.textViewTitle.setText(mList.get(position).getCName());
        holder.textViewGoodsMsg.setText(mList.get(position).getDescpT());
        holder.textViewPrice.setText(mContext.getResources().getString(R.string.symbol) + String.valueOf(mList.get(position).getPrice()));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, DetailActivity.class);
                intent.putExtra("id",Integer.parseInt(mList.get(position).getProdsId()));
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        private TextView textViewTitle,textViewGoodsMsg,textViewPrice;
        private ImageView imageViewImg;

        public MyViewHolder(View itemView) {
            super(itemView);

            textViewTitle = (TextView) itemView.findViewById(R.id.tv_goods_title_find);
            textViewGoodsMsg = (TextView) itemView.findViewById(R.id.tv_goods_msg_find);
            textViewPrice = (TextView) itemView.findViewById(R.id.tv_price_find);
            imageViewImg = (ImageView) itemView.findViewById(R.id.iv_goods_find);

        }
    }
}
